    <div class="headingBox">
        <div class="FloatLeft"><img alt="" src="<?php echo imageUrl(); ?>red_leftRound.jpg" height="24" width="5"></div>
        <div style="width:992px;" class="red_midRound"><?php echo $page_heading; ?></div>
        <div class="FloatLeft"><img alt="" src="<?php echo imageUrl(); ?>red_rightRound.jpg" height="24" width="5"></div>
    </div>
        <div>
        <?php 
			if( isset($file_error) && count($file_error) > 0 )
			{
				foreach( $file_error as $err) {
					echo '<div class="errorMsg_1" style="" align="center">'.$err.'</div>';	
				}	
				unset($err);
			}
		?>
        
        <?php 
			$id = (isset($id)) ? intval($id) : 0;
		?>
        <form method="post" action="<?php echo base_url().$this->uri->segment(1); ?>/save<?php echo ( $id > 0) ? "/$id" : ''; ?>" onsubmit="return validate();">
            <input name="sbmt" id="sbmt" value="1" type="hidden">
            <table class="subContentTable" cellpadding="2" cellspacing="5" width="100%">
                <tbody>
                <tr>
                    <td width="20%"><strong>User Name:</strong></td>
                    <td width="35%">
                        <input name="username" id="username" value="<?php echo set_value('username', isset($username) ? $username : '' ); ?>" size="30" type="text">
                        <?php echo form_error('username', '<div class="errorMsg_1" style="">', '</div>'); ?>
                    </td>
                    <td width="20%"><strong>Password:</strong></td>
                    <td width="35%">
                        <input name="password" value="<?php echo set_value('password', isset($password) ? $password : '' ); ?>" size="30" type="text">
                        <?php echo form_error('password', '<div class="errorMsg_1" style="">', '</div>'); ?>
                    </td>
                </tr>
                <tr>
                    <td width="20%"><strong>Full Name:</strong></td>
                    <td width="35%">
                        <input name="full_name" value="<?php echo set_value('full_name', isset($full_name) ? $full_name : '' ); ?>" size="30" type="text">
                        <?php echo form_error('full_name', '<div class="errorMsg_1" style="">', '</div>'); ?>
                    </td>
                    <td width="20%"></td>
                    <td width="35%">
                    </td>
                </tr>
               </tbody>
              </table>
            
            <div>&nbsp;</div>
             <div class="headingBox">
                <div class="FloatLeft"><img alt="" src="<?php echo imageUrl(); ?>red_leftRound.jpg" height="24" width="5"></div>
                <div style="width:992px;" class="red_midRound">Modules</div>
                <div class="FloatLeft"><img alt="" src="<?php echo imageUrl(); ?>red_rightRound.jpg" height="24" width="5"></div>
    		</div>
             <div>
                <table class="subContentTable" cellpadding="2" cellspacing="5" width="100%">
               
                <tr>
                    <td> 
                    	<div id="error_msg_div">
                    	<?php  
						if( count($error_arr) > 0 ) { 
							foreach( $error_arr as $err) {
								echo '<div class="errorMsg_1" style="" align="center">'.$err.'</div>';	
							}
						}
						?>
                        </div>
                      </td>
                   </tr>     
                  
                   <tr>
                   	<td>
                    
                    <div class="user_permission_div">
                     
                    	<label> <input type="checkbox" onclick="onClickCheckAll(this)" /> <span>Select All</span> </label> <br />
                    <?php 
						$user_modules_arr = array();
						if( count($user_modules) > 0 )
						{
							foreach($user_modules as $user_mod)
							{
								$permissions = explode(',', $user_mod->permission);
								foreach( $permissions as $per ) 
								{
									$user_modules_arr[$user_mod->id][$per] = $per;
								}
							}
						}
					
                     	foreach( $all_modules as $module) 
						{
							$permissions = explode(',', $module->available_actions);
							$module_checked = isset($user_modules_arr[$module->id]) ? 'checked="checked"' : '' ;
							
						?>
                        	<div style="border:1px dotted #D2D2D2; margin:2px; padding:3px; float:left; width:48%"> 
                            	<div style="padding:3px; font-weight:bold;"> 
                                	<label>
                                    <input <?php echo $module_checked; ?> style="cursor:pointer" onclick="onClickModule(this)" class="class_module_checkbox" type='checkbox' name='modules[]' id="<?php echo "module_".$module->id; ?>" value="<?php echo $module->id; ?>"  > <span> <?php echo $module->name; ?> </span>  
									</label>                                    
                               </div>
                              <?php foreach( $permissions as $per ) 
							  { 
							  	$permission_checked = isset($user_modules_arr[$module->id][$per]) ? 'checked="checked"' : '' ;
							  ?>
                               <div style="padding-left:20px; float:left; width:auto;">
                               		<label>
                                    <input <?php echo $permission_checked; ?>  style="cursor:pointer"  onclick="onClickPermission(this, '<?php echo $per;?>', '<?php echo $module->id;?>' )"  type='checkbox' class="per_<?php echo $module->id;?>" name='permissions[<?php echo $module->id;?>][<?php echo $per;?>]' value="<?php echo $per;?>" id='<?php echo $per."_".$module->id; ?>'> <span> <?php echo $per; ?></span>
                               		</label>     
                               </div>
                               <?php } ?>
                               
                               <div style="clear:both"></div>
		                   </div>
                        
						<?php
                        }
					?>
                    </div>
                    </td>
                   </tr>
                  
                </table>
                
                  <tr bgcolor="#fff1d5">
                    <td colspan="1" align="left">
                        <input value="" class="backBtn" onclick="location.href='<?php echo base_url().$this->uri->segment(1); ?>';" type="button">
                        <input value="" class="submitBtn" type="submit">
                    </td>
                </tr>
            </tbody></table>
            
            
            </div>    
            
            
        </form> 
    </div>
 <script>
	$('#agents').multiSelect({
			selectableHeader : '<h4>Available Skill</h4>',
			selectionHeader : '<h4>Assigned Skill</h4>'
		});
		
</script>
  
<script>
					function onClickCheckAll(obj)
					{
						modules  = $('.class_module_checkbox');
						for( i=0; i< modules.length; i++ ) 
						{
							if( obj.checked ) 
							{
								modules[i].checked = true;
								$('.per_'+modules[i].value).prop("checked", true);
							}
							else
							{
								modules[i].checked = false; 
								$('.per_'+modules[i].value).prop("checked", false);
							}
						}
					}

					function onClickPermission(obj, permission, module_id)
					{
						if( obj.checked ) 
						{
							$('#module_'+module_id).prop("checked", true);
							
							if ( permission == 'add' || permission == 'edit' || permission == 'delete') 
							{
								if( $('#view_'+module_id) )
								{
									$('#view_'+module_id).prop("checked", true);	
								}
							}
 						}
						else
						{
							if ( permission == 'view') 
							{
								if( $('#add_'+module_id) )
								{
									$('#add_'+module_id).prop("checked", false);	
								}
								if( $('#edit_'+module_id) )
								{
									$('#edit_'+module_id).prop("checked", false);	
								}
								if( $('#delete_'+module_id) )
								{
									$('#delete_'+module_id).prop("checked", false);	
								}
							}
						}
						
						var any_checked = false;
						permissions = $('.per_'+module_id);
						for( i=0; i< permissions.length; i++ ) 
						{
							if( permissions[i].checked ) 
							{
								any_checked = true;
							}
						}
 						if( ! any_checked ) 
						{
							$('#module_'+module_id).prop("checked", false);	
						}
					
					}
 					
					function onClickModule(obj)
					{
						module_id = obj.value;
						
						permissions = $('.per_'+module_id);
						
						for( i=0; i< permissions.length; i++ ) 
						{
							if( obj.checked )
							{
								permissions[i].checked = true;	
							} 
							else
							{
								permissions[i].checked = false;	
							}
						}
					}

					function validate()
					{
						error_msg = '';
						var any_checked = false;
							
						modules  = $('.class_module_checkbox');
						for( i=0; i< modules.length; i++ ) 
						{
							if( modules[i].checked ) 
							{
								any_checked = true;
							}
						}
						if( ! any_checked ) 
						{
							error_msg += '<div class="errorMsg_1" align="center">Please select atleast one module</div>';
						}
						
						if( error_msg == '' ) {
							$("#error_msg_div").html('');
							$("#error_msg_div").hide();	
							//return true;
						} else {
							$("#error_msg_div").html(error_msg);
							$("#error_msg_div").show();	
							return false;
						}
						
					}
							
						</script>  